{{- /*
GitLab group.

@param {string} (positional parameter 0) Group name on GitLab.

@returns {template.HTML}

@examples

  {{< gl-group "9970" >}}
*/ -}}

{{- if (.Get 0) -}}

    {{ $groups := (split (.Get 0) "|") }}
    {{ $api := (site.Params.api) }}
    {{ $ts := (now.Unix) }}
    {{ $headers := (dict
    "User-Agent" ($api.user_agent)
    "Authorization" (printf "Bearer %s" (($api.gitlab.token) | base64Decode))
    ) }}

    <div class="shortcode shortcode-{{ ($.Name) }} mb-3">
      <div class="row row-cols-1 row-cols-lg-2 g-3">
          {{ range ($groups) }}
              {{ $group := (getJSON ($api.gitlab.url) "/groups/" . "?with_projects=0&ts=" ($ts) ($headers)) }}
              {{ if (eq ($group.visibility) "public") }}
                <div class="col">
                  <div class="card">
                    <div class="row g-0">
                        {{ if ($group.avatar_url) }}
                          <div class="col-md-4 p-1">
                            <a class="d-block" href="{{ ($group.web_url) }}" target="_blank" rel="noopener nofollow">
                              <img class="card-img"
                                   src="{{ ($group.avatar_url) }}"
                                   alt="{{ (($group.name) | default ($group.path)) }}" loading="lazy"/>
                            </a>
                          </div>
                        {{ end }}
                      <div class="col">
                        <div class="card-body h-100">
                          <div class="d-flex flex-column h-100">
                            <div class="flex-shrink-0">
                              <h5 class="card-title">
                                <a href="{{ ($group.web_url) }}" target="_blank" rel="noopener nofollow">
                                    {{ (($group.name) | default ($group.path)) }}
                                </a>
                              </h5>
                              <p class="card-text">{{ (($group.description) | plainify) }}</p>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              {{ end }}
          {{ end }}
      </div>
    </div>

{{- else -}}

    {{ (partial "alerts/no_params" .) }}

{{- end -}}
